package com.banciyuan.bcywebview.utils.currency;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * Created by squall on 2016/10/27.
 */

public class CurrencyUtil {

    public static String getMoney(String money) {
        try {
            DecimalFormat myformat = new DecimalFormat("0.00");
            BigDecimal b = new BigDecimal(money);
            BigDecimal result = b.divide(new BigDecimal(100));
            int num1 = result.intValue();
            double num2 = result.doubleValue();
            if ((double) num1 == num2) {
                return String.valueOf(num1);
            } else {
                return myformat.format(result);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public static String getMoney(float money) {
        try {
            DecimalFormat myformat = new DecimalFormat("0.00");
            BigDecimal b = new BigDecimal(money);
            BigDecimal result = b.divide(new BigDecimal(100));
            int num1 = result.intValue();
            double num2 = result.doubleValue();
            if ((double) num1 == num2) {
                return String.valueOf(num1);
            } else {
                return myformat.format(result);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
